<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <!--        type 0 学生 2 职工-->
        <span>
          {{ Number(inType) == 1 ? '报名明细' : (Number(inType) == 2 ? '签到明细' : '未签到明细') }}
          {{ inType == 1 ? `【该游园共有项目 ${optionNumber}个】` : '' }}
        </span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <!--本体列表，数据 -->
        <div class="mb-10 search-list">
          <component
              v-bind:is="item.propertyType"
              :property.sync="item"
              v-for="(item, index) in getPower"
              :key="index"
              @updateVal="updateVal"
          ></component>
          <el-button type="primary" size="small" @click="searchFn('search')" class="ml-10"><i
              class="el-icon-search"></i>搜索
          </el-button>
          <el-button size="small" @click="searchFn('refresh')"><i class="el-icon-refresh"></i>重置刷新</el-button>
          <downexcel type="activeUser"
                     :option="{id: detailId,class_id:searchForm.class_id ,section_id:searchForm.section_id }"
                     v-if="inType==1" :excelName="activeTitle"></downexcel>
          <downexcel type="activeUserSign" :option="{option_id: detailId,class_id:searchForm.class_id ,section_id:searchForm.section_id }"
                     v-if="inType==2" :excelName="activeTitle"></downexcel>
        </div>
        <div class="table-body">
          <div class="table-body-box">
            <el-table
                ref="multipleTable"
                :data="arryList"
                border
                :height="tableHeight"
                tooltip-effect="dark"
                style="width: 100%"
                header-cell-class-name="table-text-c"
                cell-class-name="table-text-c">
              <el-table-column
                  prop="create_time"
                  label="报名时间"
                  v-if="Number(inType) == 1"
                  :key="1">
              </el-table-column>
              <el-table-column
                  prop="create_time"
                  label="签到时间"
                  v-if="Number(inType) == 2"
                  :key="2">
              </el-table-column>
              <el-table-column
                  label="姓名"
                  :key="3">
                <template slot-scope="scope">
                  <span v-if="Number(inType) !== 3">{{ scope.row.user ? `${scope.row.user.name}【${scope.row.user.phone}】` : '' }}</span>
                  <span v-else>{{`${scope.row.name}【${scope.row.phone}】`}}</span>
                </template>
              </el-table-column>
              <el-table-column
                  prop="create_time"
                  label="班级"
                  :key="4">
                <template slot-scope="scope">
                  {{ scope.row.type == 2 ? (scope.row.classes?scope.row.classes.class_name:'') : '' }}
                </template>
              </el-table-column>
              <el-table-column
                  prop="create_time"
                  label="身份"
                  width="70"
                  :key="5">
                <template slot-scope="scope">
                  <span v-if="scope.row.type==2">家长</span>
                  <span v-if="scope.row.type==3">访客</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="完成项目数"
                  prop="end_number"
                  width="100"
                  v-if="Number(inType) == 1"
                  :key="6">
              </el-table-column>
              <el-table-column
                  label="操作"
                  v-if="Number(inType) == 1"
                  width="90">
                <template slot-scope="scope">
                  <el-button type="danger" size="small" @click="handleDetel(scope.row)" plain>删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--        工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              :page-size="page.pagesize"
              :current-page="page.pageindex"
              layout="total, prev, pager, next"
              :total="page.total"
              @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">确定</el-button>

      </div>
    </div>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import {garden_party_user, garden_party_sign, garden_party_no_sign, garden_party_Detail, garden_party_user_delet, garden_party_option_Detail} from '@/api/admin/school'

export default {
  props: ['visible', 'detailId', 'inType'], // listType 1 报名人数 2 签到人数 3 未签到
  components: {},
  data() {
    return {
      dialogVisible: false,
      arryList: [], // 数据列表
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      tableHeight: 0,
      activeTitle: '',
      optionNumber: 0,
      searchForm: {
        class_id: '',
        section_id: ''
      },
      getPower: {
        'section_id': {
          name: 'section_id', // key名称
          default: '', // 默认值
          propertyType: "Select", // 组件名称
          placeholder: '年段', // 默认值
          valueText: '', // 值
          leve: 2,
          api: this.api.user_sectionindex, // 下拉框的请求接口
          keyName: 'section_name',// 调用的字段
          child: [
            {
              name: 'class_id',
              default: '',
              propertyType: "",
              placeholder: '班级',
              valueText: '',
              api: this.api.user_classesindex,
              keyName: 'class_name',
            }
          ]
        }
      },
    }
  },
  watch: {
    visible() {
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;
          this.tableHeight = height - (51 + 20 + 50 + 42 + 51)
        })
        this.InitFn()
      } else {
        this.arryList = [];
        this.page.pageindex = 1
        this.page.total = 0
      }
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    // 搜索组件
    searchFn(option) {
      if (option === 'refresh') {
        this.searchForm = {
          class_id: '',
          section_id: ''
        }
        this.value1 = [];
        let newGetPower = this.getJson(this.getPower)
        newGetPower['section_id'].valueText = '';
        newGetPower['section_id'].child[0].valueText = '';
        this.getPower = newGetPower;
      }
      this.page.pageindex = 1;
      this.InitFn()
    },
    // 更新值
    updateVal(option) {
      // console.log('变更数据收到的数据内容：', option)
      if (option.input) {
        this.searchForm[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.searchForm[option.select[i].name] = option.select[i].valueText
          } else {
            this.searchForm[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 初始化
    InitFn() {
      let option = JSON.parse(JSON.stringify(this.searchForm))
      option.p = this.page.pageindex
      option.id = this.detailId
      if (Number(this.inType) === 1) {
        // 游园详情
        garden_party_Detail({id: this.detailId}).then(res => {
          console.log('res:', res)
          let data_ = JSON.parse(JSON.stringify(res.vo))
          this.optionNumber = data_.option_number
          this.activeTitle = data_.title
        })
        garden_party_user(option).then(res => {
          if (!res.code) {
            // this.commitmentStatus = res.is_commitment
            for (let item of res.list.data) {
              item.user = {
                name: item.name,
                phone: item.phone
              }
            }
            this.arryList = res.list.data
            this.page.total = res.list.total
          }
        })
      } else if (Number(this.inType) === 2) {
        garden_party_option_Detail({id: this.detailId}).then(res => {
          this.activeTitle = res.vo.title
        })
        garden_party_sign(option).then(res => {
          if (!res.code) {
            this.arryList = res.list.data
            this.page.total = res.list.total
          }
        })
      } else {
        garden_party_option_Detail({id: this.detailId}).then(res => {
          this.activeTitle = res.vo.title
        })
        garden_party_no_sign(option).then(res => {
          if (!res.code) {
            this.arryList = res.list.data
            this.page.total = res.list.total
          }
        })
      }
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    checkStudent(index) {
      this.studentInfo = this.arryList[index]
      this.printvisible = true
    },
    handleDetel(row) {
      this.$confirm(`确认删除【${row.name||''}】用户报名记录 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        garden_party_user_delete({id: row.id}).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.InitFn()
            this.$emit('InitFn')
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 70%;
  height: 65%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.breadcrumb-container {
  margin-bottom: 10px;
}

.parentsList p {
  background: #f8f8f8;
  margin-bottom: 5px;
}

.parentsList p:last-child {
  margin-bottom: 0;
}

.search-list {
  display: flex;
}
</style>


